home *** CD-ROM | disk | FTP | other *** search
/ NeXT Education Software Sampler 1992 Fall / NeXT Education Software Sampler 1992 Fall.iso / Programming / c-runtime / include / objc.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-21  |  18.3 KB  |  421 lines

  1. /* -*-c-*- */
  2.  
  3. /* Copyright (C) 1989, 1992 Free Software Foundation, Inc.
  4.  
  5. This file is part of GNU CC.
  6.  
  7. GNU CC is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2, or (at your option)
  10. any later version.
  11.  
  12. GNU CC is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with GNU CC; see the file COPYING.  If not, write to
  19. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21. /* As a special exception, if you link this library with files
  22.    compiled with GCC to produce an executable, this does not cause
  23.    the resulting executable to be covered by the GNU General Public License.
  24.    This exception does not however invalidate any other reasons why
  25.    the executable file might be covered by the GNU General Public License.  */
  26.  
  27. /* 
  28.   $Header: /usr/user/dennis_glatting/ObjC/c-runtime/include/RCS/objc.h,v 0.11 1992/04/13 11:40:53 dennisg Exp dennisg $
  29.   $Author: dennisg $
  30.   $Date: 1992/04/13 11:40:53 $
  31.   $Log: objc.h,v $
  32.  * Revision 0.11  1992/04/13  11:40:53  dennisg
  33.  * Check in after array version of run-time works.
  34.  * Expect more changes as hash version and other changes are made.
  35.  *
  36.  * Revision 0.10  1991/12/31  20:16:08  dennisg
  37.  * Deleted index variable stuff.  Index variables are a hack to the language.
  38.  * Cleaned up some documentation.
  39.  *
  40.  * Revision 0.9  1991/12/10  12:04:22  dennisg
  41.  * Cleaned up file format for a distribution.
  42.  *
  43.  * Revision 0.8  1991/12/01  01:29:29  dennisg
  44.  * modified to remove changes previously made to
  45.  * implement posing.  posing just got easy.
  46.  *
  47.  * Revision 0.7  1991/11/29  22:00:10  dennisg
  48.  * modified to implement set functions.
  49.  *
  50.  * Revision 0.6  1991/11/29  20:02:01  dennisg
  51.  * fixed several const decls.  bozo.
  52.  *
  53.  * Revision 0.5  1991/11/29  00:24:14  dennisg
  54.  * many changes including posing, things to make the compiler
  55.  * happier, structure changes, and things to make it play better.
  56.  *
  57.  * Revision 0.4  1991/11/19  12:37:49  dennisg
  58.  * changed typedef and struct decls.
  59.  * the run-time was changed and those decls changed too.
  60.  *
  61.  * Revision 0.3  1991/11/16  15:57:35  dennisg
  62.  * changed the defs for class structures for new implementation of run-time.
  63.  * changed def of SEL back to its original type.
  64.  *
  65.  * Revision 0.2  1991/11/07  22:31:42  dennisg
  66.  * added copyleft.
  67.  *
  68.  * Revision 0.1  1991/10/24  00:19:24  dennisg
  69.  * Initial check in.  Preliminary development stage.
  70.  *
  71. */
  72.  
  73.  
  74. #ifndef _objc_INCLUDE_GNU
  75. #define _objc_INCLUDE_GNU
  76.  
  77.                                                 /* If someone is using a c++
  78.                                                   compiler then adjust the 
  79.                                                   types in the file back 
  80.                                                   to C. */
  81. #ifdef __cplusplus
  82. extern "C" {
  83. #endif
  84.  
  85. #include  <sys/types.h>
  86. #include  <record-inline.h>
  87. #include  <stdarg.h>
  88.  
  89.  
  90. #define nil (id)0                               /* id of Nil instance */
  91. #define Nil (Class_t)0                          /* id of Nil class */
  92. typedef char* STR;                              /* String alias */
  93.  
  94.                                                 /* Boolean typedefs */
  95. typedef char  BOOL;
  96. #define YES   (BOOL)1
  97. #define NO    (BOOL)0
  98.  
  99.                                                 /* Definition of a 
  100.                                                   selector.  Selectors are 
  101.                                                   really of type char*. The
  102.                                                   run-time hashes the 
  103.                                                   string's address to locate
  104.                                                   the method.  If the method
  105.                                                   isn't in the hash table then
  106.                                                   a search is made through the 
  107.                                                   class hierarchy using 
  108.                                                   strcmp() to locate the
  109.                                                   method. */
  110. #if 0
  111. typedef struct objc_selector*   SEL;
  112. #else
  113. typedef void* SEL;
  114. #endif
  115.  
  116.                                                 /* ObjC uses this typedef 
  117.                                                   for untyped instances. */
  118. typedef struct objc_object {
  119.   struct objc_class*  isa;
  120. } *id;
  121.  
  122.                                                 /* Prototype for method 
  123.                                                   functions. */
  124. typedef id  ( *IMP )( id, SEL, ... ); 
  125.  
  126.                                                 /* Filer types used to 
  127.                                                   describe Ivars and 
  128.                                                   Methods. */
  129. #define _C_ID       '@'
  130. #define _C_CLASS    '#'
  131. #define _C_SEL      ':'
  132. #define _C_CHR      'c'
  133. #define _C_UCHR     'C'
  134. #define _C_SHT      's'
  135. #define _C_USHT     'S'
  136. #define _C_INT      'i'
  137. #define _C_UINT     'I'
  138. #define _C_LNG      'l'
  139. #define _C_ULNG     'L'
  140. #define _C_FLT      'f'
  141. #define _C_DBL      'd'
  142. #define _C_BFLD     'b'
  143. #define _C_VOID     'v'
  144. #define _C_UNDEF    '?'
  145. #define _C_PTR      '^'
  146. #define _C_CHARPTR  '*'
  147. #define _C_ARY_B    '['
  148. #define _C_ARY_E    ']'
  149. #define _C_UNION_B  '('
  150. #define _C_UNION_E  ')'
  151. #define _C_STRUCT_B '{'
  152. #define _C_STRUCT_E '}'
  153.  
  154. /*
  155.  * These definitions are masks used with the "info" member variable in the
  156.  * class and meta class structures. 
  157.  */
  158. #define CLS_CLASS         0x1L                  /* The structure is of type
  159.                                                   class (Class_t). */
  160. #define CLS_META          0x2L                  /* The structure is of type
  161.                                                   meta class (MetaClass_t). */
  162. #define CLS_INITIALIZED   0x4L                  /* Class is initialized. A
  163.                                                   +initialize method is the
  164.                                                   first message sent to a
  165.                                                   class.  It isn't guaranteed
  166.                                                   to be sent only once. */
  167.  
  168.  
  169.                                                 /* Set this variable to !0 to
  170.                                                   have the messager print
  171.                                                   messaging operations. */
  172.   extern BOOL objc_trace;
  173.  
  174.  
  175. /*
  176.  * Whereas a Module (defined further down) is the root (typically) of a file,
  177.  * a Symtab is the root of the class and category definitions within the
  178.  * module.  
  179.  *
  180.  * A Symtab contains a variable length array of pointers to classes and
  181.  * categories  defined in the module. 
  182.  */
  183. typedef struct objc_symtab {
  184.   u_long    sel_ref_cnt;                        /* Unknown. */
  185.   SEL       *refs;                              /* Unknown. */
  186.   u_short   cls_def_cnt;                        /* Number of classes compiled
  187.                                                   (defined) in the module. */
  188.   u_short   cat_def_cnt;                        /* Number of categories 
  189.                                                   compiled (defined) in the 
  190.                                                   module. */
  191.   void      *defs[1];                           /* Variable array of pointers.
  192.                                                   cls_def_cnt of type Class_t 
  193.                                                   followed by cat_def_cnt of
  194.                                                   type Category_t. */
  195. } Symtab,   *Symtab_t;
  196.  
  197.  
  198. /*
  199.  * The compiler generates one of these structures for each module that
  200.  * composes the executable (eg main.m).  
  201.  *
  202.  * This data structure is the root of the definition tree for the module.  
  203.  *
  204.  * A collect program runs between ld stages and creates a ObjC ctor array. 
  205.  * That array holds a pointer to each module structure of the executable. 
  206.  */
  207. typedef struct objc_module {
  208.   u_long      version;                          /* Compiler revision. */
  209.   u_long      size;                             /* sizeof(Module). */
  210.   const char* name;                             /* Name of the file where the 
  211.                                                   module was generated.   The 
  212.                                                   name includes the path. */
  213.   Symtab_t    symtab;                           /* Pointer to the Symtab of
  214.                                                   the module.  The Symtab
  215.                                                   holds an array of pointers to 
  216.                                                   the classes and categories 
  217.                                                   defined in the module. */
  218. } Module, *Module_t;
  219.  
  220.  
  221. /*
  222.  * The compiler generates one of these structures for a class that has
  223.  * instance variables defined in its specification. 
  224.  */
  225. typedef struct objc_ivar* Ivar_t;
  226. typedef struct objc_ivar_list {
  227.   int   ivar_count;                             /* Number of structures (Ivar) 
  228.                                                   contained in the list.  One
  229.                                                   structure per instance 
  230.                                                   variable defined in the
  231.                                                   class. */
  232.   struct objc_ivar {
  233.     const char* ivar_name;                      /* Name of the instance
  234.                                                   variable as entered in the
  235.                                                   class definition. */
  236.     const char* ivar_type;                      /* Description of the Ivar's
  237.                                                   type.  Useful for 
  238.                                                   debuggers. */
  239.     int         ivar_offset;                    /* Byte offset from the base 
  240.                                                   address of the instance 
  241.                                                   structure to the variable. */
  242.  
  243.   } ivar_list[1];                               /* Variable length 
  244.                                                   structure. */
  245. } IvarList, *IvarList_t;
  246.  
  247.  
  248. /*
  249.  * The compiler generates one (or more) of these structures for a class that
  250.  * has methods defined in its specification. 
  251.  *
  252.  * The implementation of a class can be broken into separate pieces in a file
  253.  * and categories can break them across modules. To handle this problem is a
  254.  * singly linked list of methods. 
  255.  */
  256. typedef struct objc_method Method;
  257. typedef Method* Method_t;
  258. typedef struct objc_method_list {
  259.   struct objc_method_list*  method_next;      /* This variable is used to link 
  260.                                                 a method list to another.  It 
  261.                                                 is a singly linked list. */
  262.   int             method_count;               /* Number of methods defined in 
  263.                                                 this structure. */
  264.   struct objc_method {
  265.     SEL         method_name;                  /* This variable is the method's 
  266.                                                 name.  It is a char*. 
  267.                                                   The unique integer passed to 
  268.                                                 objc_msgSend() is a char* too.  
  269.                                                 It is compared against 
  270.                                                 method_name using strcmp(). */
  271.     const char* method_types;                 /* Description of the method's
  272.                                                 parameter list.  Useful for
  273.                                                 debuggers. */
  274.     IMP         method_imp;                   /* Address of the method in the 
  275.                                                 executable. */
  276.   } method_list[1];                           /* Variable length 
  277.                                                 structure. */
  278. } MethodList, *MethodList_t;
  279.  
  280.  
  281. /*
  282.  * The compiler generates one of these structures for each class.  
  283.  *
  284.  * This structure is the definition for meta classes. By definition a meta
  285.  * class is the class's class.  Its most relevant contribution is that its
  286.  * method list contain the class's factory methods. 
  287.  *
  288.  * This structure is generated by the compiler in the executable and used by
  289.  * the run-time during normal messaging operations.  Therefore some members
  290.  * change type. The compiler generates "char* const" and places a string in
  291.  * the following member variables:  isa and super_class. 
  292.  */
  293. typedef struct objc_metaClass {     
  294.   struct objc_metaClass*  isa;                /* Pointer to Object meta
  295.                                                 class. */
  296.   struct objc_metaClass*  super_class;        /* Pointer to meta class's
  297.                                                 super class. NULL for 
  298.                                                 Object. */
  299.   const char*             name;               /* Name of the meta class. */
  300.   long                    version;            /* Unknown. */
  301.   long                    info;               /* Bit mask.  See class masks 
  302.                                                 defined above. */
  303.   long                    instance_size;      /* Always 0 except for Object.
  304.                                                 Should be ignored. */
  305.   IvarList_t              ivars;              /* Always NULL except for 
  306.                                                 Object.  Should be ignored. */
  307.   MethodList_t            methods;            /* Linked List of factory methods 
  308.                                                 for the class. */
  309.   Record_t*               cache;              /* Pointer to factory method
  310.                                                                                                 dispatch table. */
  311. } MetaClass, *MetaClass_t;
  312.  
  313.  
  314. /*
  315.  * The compiler generates one of these structures for each class.  
  316.  *
  317.  * This structure is the definition for classes. 
  318.  *
  319.  * This structure is generated by the compiler in the executable and used by
  320.  * the run-time during normal messaging operations.  Therefore some members
  321.  * change type. The compiler generates "char* const" and places a string in
  322.  * the following member variables:  super_class. 
  323.  */
  324. typedef struct objc_class {     
  325.   MetaClass_t         isa;                    /* Pointer to the class's
  326.                                                 meta class. */
  327.   struct objc_class*  super_class;            /* Pointer to the super 
  328.                                                 class. NULL for class 
  329.                                                 Object. */
  330.   const char*         name;                   /* Name of the class. */
  331.   long                version;                /* Unknown. */
  332.   long                info;                   /* Bit mask.  See class masks 
  333.                                                 defined above. */
  334.   long                instance_size;          /* Size in bytes of the class.  
  335.                                                 The sum of the class definition 
  336.                                                 and all super class 
  337.                                                 definitions. */
  338.   IvarList_t          ivars;                  /* Pointer to a structure that
  339.                                                 describes the instance 
  340.                                                 variables in the class
  341.                                                 definition.  NULL indicates
  342.                                                 no instance variables.  Does
  343.                                                 not include super class
  344.                                                 variables. */
  345.   MethodList_t        methods;                /* Linked list of instance
  346.                                                 methods defined for the 
  347.                                                 class. */
  348.   Record_t*           cache;                  /* Pointer to instance method 
  349.                                                                                                 dispatch table. */
  350. } Class, *Class_t;
  351.  
  352.  
  353. /*
  354.  * The compiler generates one of these structures for each category.  A class
  355.  * may have many categories and contain both instance and factory methods.  
  356.  */
  357. typedef struct objc_category {
  358.   const char*   category_name;                /* Name of the category.  Name
  359.                                                 contained in the () of the
  360.                                                 category definition. */
  361.   const char*   class_name;                   /* Name of the class to which
  362.                                                 the category belongs. */
  363.   MethodList_t  instance_methods;             /* Linked list of instance
  364.                                                 methods defined in the 
  365.                                                 category. NULL indicates no
  366.                                                 instance methods defined. */
  367.   MethodList_t  class_methods;                /* Linked list of factory 
  368.                                                 methods defined in the
  369.                                                 category.  NULL indicates no
  370.                                                 class methods defined. */
  371. } Category, *Category_t;
  372.  
  373.  
  374. /*
  375.  * Structure used when a message is send to a class's super class.  The
  376.  * compiler generates one of these structures and passes it to
  377.  * objc_msgSuper(). 
  378.  */
  379. typedef struct objc_super {
  380.   id      receiver;                           /* Id of the object sending
  381.                                                 the message. */
  382.   Class_t class;                              /* Object's super class. */
  383. } Super, *Super_t;
  384.  
  385. /*
  386.  * _alloc points to the function, called through class_createInstance(), used
  387.  * to allocate memory for new instances. 
  388.  */
  389. extern id (*_alloc)(Class_t aClass);
  390. /*
  391.  * _dealloc points to the function, called through object_dispose(), used to
  392.  * free instances. 
  393.  */
  394. extern id (*_dealloc)(id aObject);
  395. /*
  396.  * _realloc points to the function, called through object_realloc(), used to
  397.  * reallocate memory for an object 
  398.  */
  399. extern id (*_realloc)(id aObject, u_int newSize);
  400.  
  401. /*
  402.  * _copy points to the function, called through object_copy(), used to create
  403.  * an exact copy of an object. 
  404.  */
  405. extern  id (*_copy)(id aObject);
  406.  
  407. /*
  408.  * _error points to the function that the run-time system calls in response
  409.  * to an error.  By default, it prints formatted error messages to the
  410.  * standard error stream and calls abort() to produce a core file. 
  411.  */
  412. extern void (*_error)(id aObject, const char* fmt, va_list ap);
  413.  
  414.  
  415. #ifdef __cplusplus
  416. }
  417. #endif
  418.  
  419.  
  420. #endif
  421.